package Test2;

import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class MyJFrame2 extends JFrame implements MouseListener {
    //创建一个按钮对象
    JButton jtb1 =new JButton("点我呀！");
    public MyJFrame2() {
        this.setSize(600, 800);
        this.setTitle("登录");
        this.setAlwaysOnTop(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLocationRelativeTo(null);
        this.setLayout(null);
        this.setVisible(true);

        jtb1.setBounds(0,0,100,50);
        //给按钮绑定鼠标事件
        jtb1.addMouseListener(this);

        this.getContentPane().add(jtb1);
        this.setVisible(true);

    }

    @Override
    public void mouseClicked(MouseEvent e) {
        System.out.println("点击了鼠标");
    }

    @Override
    public void mousePressed(MouseEvent e) {
        System.out.println("按下了鼠标");
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        System.out.println("抬起了鼠标");
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        System.out.println("鼠标进入");
    }

    @Override
    public void mouseExited(MouseEvent e) {
        System.out.println("鼠标离开");
    }
}